home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
bioinformatics.org
/
bioinformatics.org_software.tar
/
www.bioinformatics.org
/
download
/
ecell2
/
ecell220setup.exe
/
{app}
/
standard
/
SRCJ
/
Tracer.java
< prev
next >
Wrap
Text File
|
2002-05-22
|
47KB
|
1,681 lines
/**
* title: Tracer class (Tracer.java)<p>
* description : Tracer window class<p>
* Copyright (C) 1996-2001 Keio University <p>
* Copyright (C) 1998-2001 Japan Science and Technology Corporation (JST)<p>
* GNU General Public Licence <p>
* Division: Mitui Knowledge Industry Co. Ltd. Bioscience division <p>
* Version : $Id: Tracer.java,v 1.8 2002/05/13 00:23:04 ota Exp $ <p>
*/
package ecell;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.*;
import javax.swing.plaf.basic.*;
import java.util.Vector;
import java.awt.geom.*;
// 2001.7.26 akira shiozawa
import ecell.TracerDataManager;
/**
* Class for displaying Tracer window and Drawing Graphics
* @author XD.Zheng
* @version 1.0
* @since JDK1.2.2
*/
/*
public class Tracer extends JFrame implements ActionListener,AccessListener{
*/
public class Tracer extends ECell2Interface
{
JPanel jp1 = new JPanel();
JPanel jp2 = new JPanel();
JPanel jp3 = new JPanel();
GPanel grap = new GPanel(this);
JPanel jp22 = new JPanel();
JLabel label1 = new JLabel(" : ");
JLabel label2 = new JLabel(" : ");
JPanel jp31 = new JPanel();
JPanel jp32 = new JPanel();
JButton buttonClose = new JButton("Close");
JButton buttonAdd = new JButton("Add");
JButton buttonSave = new JButton("Save");
JCheckBox[] jCheckBox =new JCheckBox[8];
JRadioButton radioQuantity = new JRadioButton("quantity");
JRadioButton radioConcent = new JRadioButton("concentration");
/**
* X-coordinate beginning to clip the rectangle region
*/
int xBegin=30;
/**
* X-coordinate end to clip the rectangle region
*/
int xEnd=630;
/*
* Y-coordinate beginning to clip the rectangle region
*/
int yBegin=320;
/**
* Y-coordinate end to clip the rectangle region
*/
int yEnd=20;
/*
* Color Of Tracer Graphics
*/
Color[] gColor ={Color.blue,Color.magenta,Color.orange, Color.cyan,Color.red,Color.black,new Color(124,25,182),new Color(140,17,17)};
/**
* Substance number
*/
int[] type ={-1,-1,-1,-1,-1,-1,-1,-1} ;
/*
* Type of SubstanceWindow
*/
int[] wType ={1,1,1,1,1,1,1,1};
/**
* ClassName of Reactor
*/
String[] cName=new String[8];
/**
* Flag for start
*/
int[] first= new int[8];
/**
* Flag for magnification of the first spot
*/
int mfirst=0;
/**
* Number of Displayed Substances
*/
int arraySize = 0;
/**
* Number of current step
*/
int count =-1;
/**
* Number of previous step
*/
int oldcount =-1;
/**
* Instance of DataField
*/
DataField df;
/**
* CtrollorPanel
*/
//MainWindow window;
/**
* Tracer window number
*/
int tracerNumber =0;
/*
* Flag for maginification 0 Normal 1 Magnify
*/
int magFlag = 0;
/*
* Flag for minus
*/
int minusFlag=0;
/**
* Flag for minus when magnified
*/
int mMinusFlag=0;
/**
* Correct value for minus
*/
double correct=0.0;
/**
* Correct value for minus when maginified
*/
double mCorrect=0.0;
/**
* Maximum time
*/
double xTimeMax =0.0;
/**
* Minimum time
*/
double xTimeMin =0.0;
/**
* Maximum data
*/
double yValueMax =0.0;
/**
* Minimum data
*/
double yValueMin =0.0;
/**
* Maximum data of each substance
*/
//double[] yValueMaxs ={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
double[][] yValueMaxs =new double[2][8];
/**
* Minimum data of each substance
*/
// double[] yValueMins ={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
double[][] yValueMins = new double[2][8];
/**
* Maximum time of each substance
*/
double[] xTimeMaxs = new double[8];
// double[][] xTimeMaxs = {{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0},{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}};
/**
* Minimum time of each substance
*/
double[] xTimeMins = {-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0};
// double[][] xTimeMins = {{-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0},{-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0}};
/**
* Coordinate change rate of time
*/
double xChange=600;
/**
* Coordinate change rate of data
*/
double yChange=300;
/**
* Peak of X-coordinate
*/
double xPlot =1.0;
/**
* Peak of Y-coordinate
*/
double yPlot =1.0;
/**
* Width of X-axis
*/
int iWidth = 600;
/**
* Height of Y-axis
*/
int iHigh = 300;
/**
* Time value of a time
*/
double[] xTime = new double[8];
/**
* Data value at a step
*/
double[][] yValue = new double[2][8];
// double[] yValue = new double[8];
/**
* Time value at the previous step
*/
double[] oldXTime = new double[8];
/**
* Data value at the previous step
*/
// double[] oldYValue = new double[8];
double[][] oldYValue = new double[2][8];
/**
*
*/
// Vector[] vTime = new Vector[8];
/**
* All data values
*/
// Vector[] vValue = new Vector[8];
/**
* X-coordinate at the first point
*/
int mx0 = 0;
/**
* Y-coordinate at the first point
*/
int my0 = 0;
/**
* X-coordinate at the second point
*/
int mx1 = 0;
/**
* Y-coordinate at the second point
*/
int my1 = 0;
/**
* Rate on magnification in the X-axis
*/
double mxChange=600;
/**
* Rate on magnification in the Y-axis
*/
double myChange=300;
/**
* Initial value for the range of magnification along the time
*/
double mxTimeBegin =0.0;
/**
* Final value for the range of magnification along the time
*/
double mxTimeEnd =0.0;
/**
* Final value for the range of magnification for the data
*/
double myValueBegin =0.0;
/**
* Final value for the range of magnification for the data
*/
double myValueEnd =0.0;
/**
* Range of the magnified state in the X-axis
*/
double mxPlot =0.0;
/**
* Range of the magnified state in the Y-axis
*/
double myPlot =0.0;
/**
* coordinates of four vertrices to specify the range for maginification
*/
int rx0;
int ry0;
int rx1;
int ry1;
/**
* Cursor x
*/
public static double mousex =0;
/**
* Cursor y
*/
public static double mousey =0;
/**
* Flag for dragging with mouse
*/
boolean rflag =false;
/**
* 2001.7.26 akira shiozawa
*/
TracerDataManager dman = new TracerDataManager();
/**
* 2002.1.23 flag for quantity(0)/concentration(1) mode
*/
protected int nTracerFlag = 0;
/**
* Constructor
* @param window Control Panel
*/
public Tracer(MainWindow window) {
// 2002.4. akira shiozawa
super( window );
jbInit();
}
/**
* Constructor
* @param window Control Panel
* @param number Number of the window, called by the control panel
*/
public Tracer(MainWindow window,int number){
// 2002.4. akira shiozawa
super( window );
tracerNumber = number;
try {
//this.window = window;
jbInit();
window.addAccessListener( this );
}
catch(Exception e) {
window.messageWindow.setErrorMessage( e );
}
}
/**
* Initialization
* @return void
*/
public void jbInit()/* throws Exception */{
this.setResizable(true);
this.getContentPane().setBackground(Color.lightGray);
//this.setSize(new Dimension(670, 470));
this.setSizeAndLocation(new Dimension(670, 470), new Point(150, 100));
this.setTitle("Tracer");
buttonClose.addActionListener(this);
buttonAdd.addActionListener(this);
buttonSave.addActionListener(this);
jp1.setLayout(new FlowLayout(0,2,0));
jp1.setPreferredSize(new Dimension(500,51));
jp31.setLayout(new FlowLayout(0,0,0));
jp31.add(buttonClose);
jp31.add(buttonAdd);
jp31.add(buttonSave);
for(int i=0;i<8;i++){
// 2001.6.28 comment out by akira shiozawa
/*
vTime[i] = new Vector();
vValue[i] = new Vector();
*/
jCheckBox[i]=new JCheckBox();
jCheckBox[i].addMouseListener( myMouseAdapter);
jCheckBox[i].addActionListener(this);
jCheckBox[i].setVisible(false);
jCheckBox[i].setForeground(gColor[i]);
}
grap.setBackground(Color.white);
grap.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(Color.white,new Color(178, 178, 178)),BorderFactory.createEmptyBorder(5,5,5,5)));
grap.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (e.getModifiers() == e.BUTTON1_MASK){
int pointx = e.getX();
int pointy = e.getY();
Tracer.mousex = 0.0;
Tracer.mousey = 0.0;
pointx = pointx - xBegin;
pointy = yBegin - pointy;
if(magFlag==0){
double dx = pointx/xChange;
double dy= pointy/yChange;
if(dx>=0 && dy>=0 && pointx <= iWidth && pointy <= iHigh){
double my=dy-correct;
//label1.setText(""+ getDoubleValue(dx) +":" + getDoubleValue(my));
Tracer.mousex = dx;
Tracer.mousey = /*dy*/my;
}
/**
else{
//label1.setText(" : ");
}
**/
}else if(magFlag==1){
double dx = pointx/mxChange + mxTimeBegin;
double dy = pointy/myChange+ myValueBegin;
if(dx>=mxTimeBegin && dy>=myValueBegin && dx <= mxTimeEnd && dy <= myValueEnd){
double my= dy-mCorrect;
//label1.setText(""+ getDoubleValue(dx) +":" + getDoubleValue(my));
Tracer.mousex = dx;
Tracer.mousey = /*dy*/my;
}
/**
else{
//label1.setText(" : ");
}
**/
}
// 2002.5
//grap.repaint();
window.repaintAllTracers();
}else if(e.getModifiers() == e.BUTTON3_MASK){
if(e.getClickCount()==1){
rx0 = e.getX();
ry0 = e.getY();
if(rx0<xBegin)
rx0=xBegin;
if(rx0>(xBegin +iWidth))
rx0=xBegin+iWidth;
if(ry0>yBegin)
ry0 = yBegin;
if(ry0<(yBegin-iHigh))
ry0= yBegin -iHigh;
}else if(e.getClickCount()==2){
magFlag=0;
grap.repaint();
}
}
}
public void mouseReleased(MouseEvent me) {
if(me.getModifiers() == me.BUTTON3_MASK){
//System.out.println( "rflag:" + rflag + "/rx0:" + rx0 + "/rx1:" + rx1 + "/ry0:" + ry0 + "/ry1:" + ry1 );
if(rflag ==true && rx0!=rx1 && ry0!=ry1){
rflag =false;
if(rx1>rx0){
mx1 =rx1;
mx0=rx0;
}else{
mx1 =rx0;
mx0=rx1;
}
if(ry1>ry0){
my0 =ry1;
my1=ry0;
}else{
my0 =ry0;
my1=ry1;
}
magnifyTracer();
}
rflag=false;
rx0=0;
ry0=0;
rx1=0;
ry1=0;
grap.repaint();
}
}
});
grap.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e){
if(e.getModifiers() == e.BUTTON3_MASK){
rflag=true;
rx1 = e.getX();
ry1 = e.getY();
if(rx1<xBegin)
rx1=xBegin;
if(rx1>(xBegin +iWidth))
rx1=xBegin+iWidth;
if(ry1>yBegin)
ry1 = yBegin;
if(ry1<(yBegin-iHigh))
ry1= yBegin -iHigh;
if(rx0<xBegin)
rx0=xBegin;
if(rx0>(xBegin +iWidth))
rx0=xBegin+iWidth;
if(ry0>yBegin)
ry0 = yBegin;
if(ry0<(yBegin-iHigh))
ry0= yBegin -iHigh;
grap.repaint();
}
}
public void mouseMoved(MouseEvent e) {
int pointx = e.getX();
int pointy = e.getY();
//pointx = pointx -30;
pointx = pointx - xBegin;
//pointy = 320-pointy;
pointy = yBegin - pointy;
if(magFlag==0){
double dx = pointx/xChange;
double dy= pointy/yChange;
if(dx>=0 && dy>=0){
double my=dy-correct;
label2.setText(""+ getDoubleValue(dx) +":" + getDoubleValue(my));
}else{
label2.setText(" : ");
}
}else if(magFlag==1){
double dx = pointx/mxChange + mxTimeBegin;
double dy = pointy/myChange+ myValueBegin;
if(dx>=mxTimeBegin && dy>=myValueBegin){
double my=dy-mCorrect;
label2.setText(""+ getDoubleValue(dx) +":" + getDoubleValue(my));
}else{
label2.setText(" : ");
}
}
}
});
// 2002.3.25 akira shiozawa
this.addComponentListener( new ComponentAdapter() {
public void componentResized( ComponentEvent e )
{
xEnd = (grap.getWidth() - grap.xMarginR);
yBegin = (grap.getHeight() - grap.yMarginB);
if( magFlag != 0 )
{
// 2002.3.25 akira shiozawa
iWidth = xEnd - xBegin;
iHigh = yBegin - yEnd;
mxChange =iWidth/(mxTimeEnd-mxTimeBegin);
if(mxChange<0) mxChange =- mxChange;
myChange = iHigh/(myValueEnd-myValueBegin);
if(myChange<0) myChange = - myChange;
}
}
});
jp1.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142)),"Tracer"));
for(int i=0; i<8;i++){
jp1.add(jCheckBox[i]);
}
jp2.setLayout(new BorderLayout());
jp2.add(grap,"Center");
jp22.setLayout(new FlowLayout(0,30,3));
jp22.add(label1);
jp22.add(label2);
jp2.add(jp22,"South");
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(radioQuantity);
buttonGroup.add(radioConcent);
jp32.setLayout(new FlowLayout(2,0,0));
jp32.add(radioQuantity);
jp32.add(radioConcent);
// 2002.1.23 akira shiozawa
radioQuantity.addActionListener( this );
radioConcent.addActionListener( this );
radioQuantity.setSelected( true );
jp3.setLayout(new BorderLayout());
jp3.add(jp31,"West");
jp3.add(jp32,"East");
this.getContentPane().add(jp1,"North");
this.getContentPane().add(jp2,"Center");
this.getContentPane().add(jp3,"South");
// 2002.1.16
this.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
// 2002.2.19 get current time
xTimeMax = window.df.getTime();
//System.out.println( "current time:" + xTimeMax );
}
/**
* Access event processing
* @param win Instance of MainWindow
* @return void
*/
public void accessJni( MainWindow win) {
// 2001.10.19 stop running when io exception has occurred
try
{
setRunningFlag( true );
if( !grap.bPainting )
{
drawTracer();
}
setRunningFlag( false );
}
catch( java.io.IOException e )
{
window.messageWindow.setErrorMessage( e );
//Object message = e.getMessage();
String title ="E-Cell Tracer";
int type = JOptionPane.INFORMATION_MESSAGE;
JOptionPane.showMessageDialog( this, e.getMessage(), title, type );
window.stopAction();
return;
}
}
/**
* Action event processing
* @param e Instance of ActionEvent
* @return void
*/
public void actionPerformed(ActionEvent e) {
for(int i=0;i<arraySize;i++){
if(e.getSource()==jCheckBox[i]){
// 2002.1.23 akira shiozawa
getMaxValue();
defineScale();
this.repaint();
break;
}
}
if(e.getSource() == buttonClose){
if( confirmExit() )
{
exit_actionPerformed();
}
}
if(e.getSource() == buttonAdd){
if(window.selectorFlag==false){
window.selector = new EntrySelector(0,window);
window.selectorFlag = true;
window.selector.setTracer(this);
window.selector.setVisible(true);
window.selector.setLocation(150,100);
}else{
if(window.selector.isVisible()){
Object message ="Entry Selector is be using by other window";
String title ="E-Cell Tracer";
int messageType = JOptionPane.INFORMATION_MESSAGE;
JOptionPane.showMessageDialog(this,message,
title,messageType);
return;
}
window.selector.setEntrySelector(0);
window.selector.setTracer(this);
window.selector.setVisible(true);
}
try{
window.df.setTracerState(tracerNumber,1);
}catch(Exception ex){
window.messageWindow.setErrorMessage( ex );
}
}
if(e.getSource() == buttonSave){
window.df.saveTracer(tracerNumber);
}
// 2002.1.23 for concentration
if( e.getSource() == radioQuantity ||
e.getSource() == radioConcent )
{
int flg = (e.getSource() == radioConcent)? 1 : 0;
if( nTracerFlag != flg )
{
nTracerFlag = flg;
Tracer.mousex = Tracer.mousey = 0.0;
magFlag = 0;
getMaxValue();
defineScale();
this.repaint();
}
}
}
/**
* Set item of Tracer
* @param tracerList Substance name displayed on the window
* @param kits Mouse right button The character string displayed upon drawing
* @param className Meaningless if it is Reactor or Substance class
* @param objCodes Substance number
* @param objType Substance type
* @return void
*/
public void setCheckBox(String[] tracerList,String[] kits,String[] className,int[] objCodes,int[] objType){
int size = tracerList.length;
int plus = arraySize + size;
// 2002.1.23 akira shiozawa
double data[] = new double[7];
if(plus <8){
for(int i= arraySize;i<plus;i++){
jCheckBox[i].setText(tracerList[i-arraySize]);
jCheckBox[i].setVisible(true);
jCheckBox[i].setSelected(true);
jCheckBox[i].setToolTipText(kits[i-arraySize]);
type[i] =objCodes[i-arraySize];
wType[i] = objType[i-arraySize];
cName[i] = className[i-arraySize];
}
arraySize = plus;
}else {
buttonAdd.setEnabled(false);
for(int i= arraySize;i<8;i++){
jCheckBox[i].setText(tracerList[i-arraySize]);
jCheckBox[i].setVisible(true);
jCheckBox[i].setSelected(true);
jCheckBox[i].setToolTipText(kits[i-arraySize]);
type[i]=objCodes[i-arraySize];
wType[i]=objType[i-arraySize];
cName[i] = className[i-arraySize];
}
arraySize = 8;
}
// 2002.5
if( xTimeMax == xTimeMin )
{
for( int i = 0; i < arraySize; i++ )
{
window.df.getInitValues( type[i], data );
//System.out.println( "e_no:" + type[i] + "/time:" + data[0] + "/data:" + data[1] + "/concent:" + data[4] );
try
{
dman.appendTracerData( (tracerNumber + "-" + i + "-" + type[i]), data );
oldXTime[i] = data[0];
oldYValue[0][i] = data[1];
oldYValue[1][i] = data[4];
yValueMaxs[0][i] = data[1];
yValueMins[0][i] = data[1];
yValueMaxs[1][i] = data[4];
yValueMins[1][i] = data[4];
}
catch( Exception e )
{
window.messageWindow.setErrorMessage( e );
}
}
}
}
/**
* Calculate the new maximum data by comparing the previous maximum data and the latest one.
* @return void
*/
private void getMaxValue(){
int flag =0;
for(int i=0;i<arraySize;i++){
if(jCheckBox[i].isSelected()){
if(flag==0 ){
xTimeMax=xTimeMaxs[i];
xTimeMin=xTimeMins[i];
yValueMax=yValueMaxs[nTracerFlag][i];
yValueMin=yValueMins[nTracerFlag][i];
flag=1;
}else{
if(xTimeMin>xTimeMins[i])
xTimeMin=xTimeMins[i];
if(xTimeMax<xTimeMaxs[i])
xTimeMax=xTimeMaxs[i];
if(yValueMin>yValueMins[nTracerFlag][i])
yValueMin=yValueMins[nTracerFlag][i];
if(yValueMax<yValueMaxs[nTracerFlag][i])
yValueMax=yValueMaxs[nTracerFlag][i];
}
}
}
if(flag ==0){
xTimeMax =0.0;
yValueMax =0.0;
xTimeMin=0.0;
yValueMin=0.0;
}
}
public boolean defineScale()
{
double oldXPlot=xPlot;
double oldYPlot=yPlot;
boolean ret = false;
xPlot = ceilToPow10(xTimeMax);
if(yValueMax>=0 && yValueMin>=0){
minusFlag=0;
yPlot = ceilToPow10(yValueMax);
correct=0;
}
if(yValueMax>0 && yValueMin<0){
minusFlag=1;
if(yValueMax>=-yValueMin)
yPlot =2* ceilToPow10(yValueMax);
else
yPlot =2* ceilToPow10(-yValueMin);
correct=0.5*yPlot;
}
if(yValueMax<=0 && yValueMin<0){
minusFlag=2;
yPlot = ceilToPow10(-yValueMin);
correct=yPlot;
}
if (oldXPlot!=xPlot ||oldYPlot!=yPlot){
// 2002.3.25 comment out
//mousex=0;
//mousey=0;
//this.repaint();
ret = true;
}
iWidth = xEnd - xBegin;
iHigh = yBegin - yEnd;
xChange = iWidth/xPlot;
yChange = iHigh/yPlot;
//System.out.println( "xChange:" + xChange + "/yChange:" + yChange + "/xPlot:" + xPlot + "/yPlot:" + yPlot + "/xTimeMax:" + xTimeMax + "/yValueMax:" + yValueMax + "/xTimeMin:" + xTimeMin + "/yValueMin:" + yValueMin );
return ret;
}
private void getTracerData( int i )
{
double[] data = new double[7];
try
{
//System.out.println( "getTracerData(no." + tracerNumber + ")" );
window.df.getTracerData(0,type[i],data);
xTime[i]=data[0];
if(xTime[i] > 0.0)
{
if(xTimeMins[i] < 0.0)
{
xTimeMins[i]=data[0];
}
xTimeMaxs[i]=data[0];
yValue[0][i]=data[1];
if( yValueMaxs[0][i]<data[1])
{
yValueMaxs[0][i] = data[1];
}
if(yValueMins[0][i]>data[1])
{
yValueMins[0][i] = data[1];
}
// 2002.1.23 for concentration
yValue[1][i] = data[4];
if( yValueMaxs[1][i] < data[4] )
{
yValueMaxs[1][i] = data[4];
}
if( yValueMins[1][i] > data[4] )
{
yValueMins[1][i] = data[4];
}
dman.appendTracerData( (tracerNumber + "-" + i + "-" + type[i]), data );
}
else
{
//System.out.println( "index:" + i + " time=0 quantity=" + data[1] );
}
}
catch(Exception ex)
{
window.messageWindow.setErrorMessage( ex );
}
}
/**
* Draw Graphics
* @return void
*/
private void drawTracer() throws java.io.IOException
{
Graphics g = grap.getGraphics();
count++;
//double[] data;
for(int i=0;i<arraySize;i++)
{
getTracerData( i );
}
getMaxValue();
if( defineScale() )
{
this.repaint();
}
//System.out.println( "oldXTime[1-8]:" + oldXTime[0] + "," + oldXTime[1] + "," + oldXTime[2] + "," + oldXTime[3] + "," + oldXTime[4] + "," + oldXTime[5] + "," + oldXTime[6] + "," + oldXTime[7] );
int y1=0;
int y0=0;
for(int i=0;i<arraySize;i++){
// 2002.1.24 akira shiozawa
if( xTime[i] <= 0 )
{
if( xTime[i] == 0 )
{
first[i]=1;
}
continue;
}
if(magFlag==0){
//System.out.println( "first[i]:" + first[i] + "/selected:" + jCheckBox[i].isSelected() + "/xTime[i]:" + xTime[i] );
if(first[i]==1 && jCheckBox[i].isSelected() ){
/*
if(minusFlag==1){
y1 =(int)( (yValue[i]+0.5*yPlot)*yChange);
y0 =(int)((yValue[i]+0.5*yPlot)*yChange);
}else if(minusFlag==2){
y1 =(int)( (yValue[i]+yPlot)*yChange);
y0 =(int)((yValue[i]+yPlot)*yChange);
}else{
y1= (int)(yValue[i]*yChange);
y0 =(int)(oldYValue[i]*yChange);
} */
//System.out.println( "type:" + type[i] + "/oldXTime:" + oldXTime[i] );
y1=(int)((yValue[nTracerFlag][i]+correct)*yChange);
y0=(int)((oldYValue[nTracerFlag][i]+correct)*yChange);
int x1= (int) (xTime[i]*xChange);
int x0= (int)(oldXTime[i]*xChange);
g.setColor(gColor[i]);
g.drawLine(x0+ xBegin ,yBegin-y0, x1+ xBegin,yBegin-y1);
}
}else{
if(mfirst==0) this.repaint();
mfirst=1;
if(jCheckBox[i].isSelected() && xTime[i]>=mxTimeBegin && xTime[i]<=mxTimeEnd
&& (yValue[nTracerFlag][i]+mCorrect)>=myValueBegin && (yValue[nTracerFlag][i]+mCorrect)<=myValueEnd)
{
int x1=(int)((xTime[i]-mxTimeBegin)*mxChange);
int x0=(int)((oldXTime[i]-mxTimeBegin)*mxChange);
if(x0<0) x0=0;
y1=(int)((yValue[nTracerFlag][i]+mCorrect-myValueBegin)*myChange);
y0=(int)((oldYValue[nTracerFlag][i]+mCorrect-myValueBegin)*myChange);
if(y0<0) y0=0;
g.setColor(gColor[i]);
int dy0=yBegin-y0;
int dy1=yBegin-y1;
if(dy0>yBegin) dy0=yBegin;
if(dy0<yEnd) dy0=yEnd;
if(dy1>yBegin) dy1=yBegin;
if(dy1<yEnd) dy1=yEnd;
g.drawLine(x0+ xBegin ,dy0, x1+ xBegin,dy1);
}
}
first[i]=1;
oldXTime[i]=xTime[i];
oldYValue[0][i]=yValue[0][i];
oldYValue[1][i]=yValue[1][i];
}
}
/**
* Convert Double value to suitable String.
* @param vaule Double data
* @return Converted String
*/
public String getDoubleValue(double value){
int dotIndex=-1;
int eIndex=-1;
String str=String.valueOf(value);
int len=str.length();
if(len<=8) return str;
dotIndex=str.indexOf(".");
eIndex=str.indexOf("E");
if(eIndex==-1){
if(dotIndex==-1){
return str;
}else if(dotIndex==7){
return str.substring(0,9);
}else if(dotIndex<7){
return str.substring(0,8);
}else if(dotIndex>7){
return str.substring(0,dotIndex);
}
}else if(eIndex<=7){
return str;
}else{
return (str.substring(0,7)+str.substring(eIndex,len));
}
return "";
}
/**
*Magnify
*@return void
*/
private void magnifyTracer(){
//System.out.println( "magnifyTracer/magFlag:" + magFlag );
int beforeFlag =0;
double dxBegin=0.0;
double dxEnd=0.0;
double dyBegin = 0.0;
double dyEnd =0.0;
int ixBegin;
int ixEnd;
int iyBegin;
int iyEnd;
mfirst=0;
// 2002.3.25 comment out
//mousex=0;
//mousey=0;
if(magFlag ==0){
beforeFlag=0;
magFlag =1;
}else{
beforeFlag=1;
}
//System.out.println( "xPlot:" + xPlot + "/yPlot:" + yPlot + "/iWidth:" + iWidth + "/iHigh:" + iHigh + "xBegin:" + xBegin + "/yBegin:" + yBegin + "/mx0:" + mx0 + "/mx1:" + mx1 + "/my0:" + my0 + "/my0:" + my1 );
if(beforeFlag==0){
mMinusFlag=minusFlag;
mCorrect=correct;
dxBegin = (mx0-xBegin)*xPlot/iWidth;
dxEnd = (mx1-xBegin)*xPlot/iWidth;
dyBegin = (yBegin-my0)*yPlot/iHigh;
dyEnd = (yBegin-my1)*yPlot/iHigh;
ixBegin=(int)dxBegin;
ixEnd =(int)dxEnd;
iyBegin=(int)dyBegin;
iyEnd =(int)dyEnd;
// if((ixEnd-ixBegin==0.0)||(Math.abs(dyEnd-dyBegin)<0.000001)) return;
double xxx = Math.abs(dxEnd-dxBegin);
double yyy = Math.abs(dyEnd-dyBegin);
//System.out.println( "xxx:" + xxx + "/yyy:" + yyy );
if( xxx == 0.0 || yyy == 0.0 )
return;
mxTimeBegin=(double)dxBegin;
mxTimeEnd =(double) dxEnd;
myValueBegin=dyBegin;
myValueEnd=dyEnd;
mxChange =iWidth/(mxTimeEnd-mxTimeBegin);
if(mxChange<0) mxChange =-mxChange;
myChange = iHigh/(myValueEnd-myValueBegin);
if(myChange<0) myChange = -myChange;
mxPlot=mxTimeEnd-mxTimeBegin;
myPlot=myValueEnd-myValueBegin;
}else if(beforeFlag == 1){
dxBegin = (mx0-xBegin)*mxPlot/iWidth+mxTimeBegin;
dxEnd = (mx1-xBegin)*mxPlot/iWidth+mxTimeBegin;
dyBegin = (yBegin-my0)*myPlot/iHigh+myValueBegin;
dyEnd = (yBegin-my1)*myPlot/iHigh+myValueBegin;
ixBegin=(int)dxBegin;
ixEnd =(int)dxEnd;
iyBegin=(int)dyBegin;
iyEnd =(int)dyEnd;
//System.out.println( "dxEnd:" + dxEnd + "/dxBegin:" + dxBegin + "/dyEnd:" + dyEnd + "/dyBegin:" + dyBegin );
window.messageWindow.setDebugMessage( "dxEnd:" + dxEnd + "/dxBegin:" + dxBegin + "/dyEnd:" + dyEnd + "dyBegin:" + dyBegin );
if( ( Math.abs( dxEnd - dxBegin ) < 0.000001 ) ||
( Math.abs( dyEnd - dyBegin ) < 0.000001 ) )
{
return;
}
mxTimeBegin=(double)dxBegin;
mxTimeEnd =(double) dxEnd;
myValueBegin=dyBegin;
myValueEnd=dyEnd;
mxChange =iWidth/(mxTimeEnd-mxTimeBegin);
if(mxChange<0) mxChange =-mxChange;
myChange = iHigh/(myValueEnd-myValueBegin);
if(myChange<0) myChange = -myChange;
mxPlot=mxTimeEnd-mxTimeBegin;
myPlot=myValueEnd-myValueBegin;
}
window.messageWindow.setDebugMessage( "mxTimeBegin:" + mxTimeBegin + "/mxTimeEnd:" + mxTimeEnd + "/myValueBegin:" + myValueBegin + "/myValueEnd:" + myValueEnd + "/mxChange:" + mxChange + "/myChange:" + myChange + "/mxPlot:" + mxPlot + "/myPlot:" + myPlot );
//System.out.println( "mxTimeBegin:" + mxTimeBegin + "/mxTimeEnd:" + mxTimeEnd );
//System.out.println( "myValueBegin:" + myValueBegin + "/myValueEnd:" + myValueEnd );
}
/**
* Calculate the coordinate
* @return double X or Y-coordinate
* @param xxx X or Y-maximum
*/
private synchronized double ceilToPow10(double xxx){
if(xxx==0.0) {
return 1.0;
}
double tmp =1.0;
if(1.0<xxx){
while(tmp<xxx){
tmp *= 10.0;
}
}else {
while(xxx<=tmp){
tmp*=0.1;
}
tmp*=10.0;
}
if(tmp>1.0 && xxx<0.5*tmp) tmp =0.5*tmp;
return tmp;
}
/**
* Override to exit when the window is closed.
* @return void
* @param e WindowEvent
*/
/*
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
if( confirmExit() )
{
exit_actionPerformed();
}
}
}
*/
/**
* Override to exit confirming when the window is closed.
* @return boolean
*/
protected boolean confirmExit()
{
Object confirmText ="Really want to close this Tracer?";
String confirmTitle ="Tracer";
int optionType = JOptionPane.YES_NO_OPTION;
int messageType = JOptionPane.QUESTION_MESSAGE;
int selectedValue =JOptionPane.showConfirmDialog(this.getContentPane(),confirmText,
confirmTitle,optionType,messageType);
return (selectedValue == 0)? true : false;
}
/*
* Close the window.
* @return void
*/
public void exit_actionPerformed()
{
try
{
// 2002.3.5
window.removeAccessListener( this );
while( getRunningFlag() )
{
Thread.sleep( 50 );
}
this.setVisible(false);
// 2002.1.16
this.dman.deleteTempFiles();
//System.out.println( "setTracerState@exit_actionPerformed(no." + tracerNumber + ")" );
window.df.setTracerState(tracerNumber,-1);
}catch(Exception ex){
window.messageWindow.setErrorMessage( ex );
}
this.dispose();
}
/**
* Exiting process
* @return void
*/
public void exitTracer()
{
exit_actionPerformed();
}
/**
*Adapter
*/
MouseAdapter myMouseAdapter = new MouseAdapter(){
public void mousePressed(MouseEvent e) {
if (e.getModifiers() == e.BUTTON3_MASK){
int i=0;
for(i=0;i<arraySize;i++){
if(e.getSource()==jCheckBox[i])
break;
}
if(wType[i]==1){
try{
window.df.setEntrySelected(-1,1,type[i]);
}catch (Exception ex){
window.messageWindow.setErrorMessage( ex );
}
Substance substance = new Substance(type[i],jCheckBox[i].getText(),
jCheckBox[i].getToolTipText(),window);
//window.vSubstance.addElement(substance);
substance.setVisible(true);
substance.setLocation(150+i*20,100+i*10);
}
if(wType[i]==2){
try{
window.df.setEntrySelected(-1,2,type[i]);
}catch(Exception ex){
window.messageWindow.setErrorMessage( ex );
}
Reactor reactor = new Reactor(type[i],jCheckBox[i].getText(),
jCheckBox[i].getToolTipText(),cName[i],window);
//window.vReactor.addElement(reactor);
reactor.setVisible(true);
reactor.setLocation(150+i*20,100+i*10);
}
}
}
};
}
/**
* Graphics panel class
* @author XD.Zheng
* @version 1.0
* @since JDK1.2.2
*/
class GPanel extends JPanel{
/**
* Instance of parent Tracer
*/
Tracer tracer;
// 2000.06.28 akira shiozawa
private final int maxdata = 4096;
volatile double data[][] = new double[maxdata][7];
// 20002.3.19 akira shiozawa
private FontMetrics fontInfo = null;
public final int xMarginL = 30;
public final int xMarginR = 32;
public final int yMarginT = 20;
public final int yMarginB = 22;
public boolean bPainting = false;
/*
* Constructor
*param tracer Parent Tracer
*/
public GPanel(Tracer tracer){
int rx0=0;
int ry0=0;
int rx1=0;
int rx2=0;
this.tracer = tracer;
}
/**
* Component drawing
*@return void
*@param g Graphics Object
*/
public void paintComponent(Graphics g) {
super.paintComponent(g);
// 2002.4 akira shiozawa
this.bPainting = true;
tracer.window.messageWindow.setDebugMessage( "----- tracerNumber:" + tracer.tracerNumber + "-paintComponent@" + getClass()+getName() );
int y1=0;
int y0=0;
int x0=0;
int x1=0;
if( fontInfo == null )
{
fontInfo = g.getFontMetrics();
}
//System.out.println( "Dimension:" + this.getWidth() + "/" + this.getHeight() + "//" + fontInfo.getMaxAdvance() );
//System.out.println( "xEnd:" + tracer.xEnd + "/yBegin:" + tracer.yBegin );
// 2002.1.23 for concentration
int valueIndex = (tracer.nTracerFlag == 1)? 4 : 1;
if(tracer.magFlag ==0){
tracer.defineScale();
if(tracer.minusFlag==0){
g.drawString(""+tracer.getDoubleValue(tracer.yPlot) ,
tracer.xBegin, (tracer.yEnd - fontInfo.getDescent()) );
g.drawString("0", tracer.xBegin, (tracer.yBegin + fontInfo.getAscent()) );
}else if(tracer.minusFlag==1){
g.drawString(""+tracer.getDoubleValue(tracer.correct) ,
tracer.xBegin, (tracer.yEnd - fontInfo.getDescent()));
g.drawString("-"+tracer.getDoubleValue(tracer.correct),
tracer.xBegin,(tracer.yBegin + fontInfo.getAscent()));
}else {
g.drawString("0", tracer.xBegin, (tracer.yEnd - fontInfo.getDescent()));
g.drawString("-"+ tracer.getDoubleValue(tracer.correct),
tracer.xBegin,(tracer.yBegin + fontInfo.getAscent()));
}
String str = tracer.getDoubleValue( tracer.xPlot );
g.drawString( str, (tracer.xEnd - fontInfo.stringWidth( str ) / 2),
(tracer.yBegin + fontInfo.getAscent()));
g.setColor(Color.lightGray);
g.drawRect( tracer.xBegin, tracer.yEnd,
(tracer.xEnd - tracer.xBegin), (tracer.yBegin - tracer.yEnd) );
g.setColor(getForeground());
for(int j=0;j<8;j++){
if(tracer.jCheckBox[j].isSelected()){
g.setColor(tracer.gColor[j]);
// ---> 2001.6.28 akira shiozawa
int index = 0;
int max = -1;
do
{
max = tracer.dman.getTracerDataBlock(
(tracer.tracerNumber + "-" + j + "-" + tracer.type[j]),
data, index, maxdata );
//System.out.println( "tracer.type:" + tracer.type[j] + "/max:" + max );
if( max <= 0 )
{
break;
}
for( int i = 1; i < max; i++, index++ )
{
double dx1= data[i][0];
double dx0= data[i-1][0];
double dy1= data[i][valueIndex] + tracer.correct;
double dy0= data[i-1][valueIndex] + tracer.correct;
x1= (int) (dx1*tracer.xChange);
x0= (int)(dx0*tracer.xChange);
y1=(int)(dy1*tracer.yChange);
y0=(int)(dy0*tracer.yChange);
g.drawLine(x0+ tracer.xBegin ,tracer.yBegin-y0,
x1+ tracer.xBegin,tracer.yBegin-y1);
}
}while( max > 0 );
// <--- akira shiozawa
}
}
}else{
g.setColor(Color.lightGray);
g.drawRect( tracer.xBegin, tracer.yEnd,
(tracer.xEnd - tracer.xBegin), (tracer.yBegin - tracer.yEnd) );
for(int j=0;j<8;j++){
if(tracer.jCheckBox[j].isSelected()){
g.setColor(tracer.gColor[j]);
// ---> 2001.6.28 akira shiozawa
int index = 0;
int max = -1;
do
{
max = tracer.dman.getTracerDataBlock(
(tracer.tracerNumber + "-" + j + "-" + tracer.type[j]),
data, index, maxdata );
if( max <= 0 )
{
break;
}
for( int i = 1; i < max; i++, index++ )
{
double dx0= data[i-1][0];
double dx1= data[i][0];
double dy0= data[i-1][valueIndex] + tracer.correct;
double dy1= data[i][valueIndex] + tracer.correct;
// 2002.4 akira shiozawa
Point2D.Double p0 = new Point2D.Double( dx0, dy0 );
Point2D.Double p1 = new Point2D.Double( dx1, dy1 );
if( getDrawPoints( p0, p1 ) )
{
y1= (int)((p1.getY()-tracer.myValueBegin)*tracer.myChange);
x1= (int)((p1.getX()-tracer.mxTimeBegin)*tracer.mxChange);
x0= (int)((p0.getX()-tracer.mxTimeBegin)*tracer.mxChange);
y0 =(int)((p0.getY()-tracer.myValueBegin)*tracer.myChange);
/**/
tracer.window.messageWindow.setDebugMessage( "xy0(" + x0 + "," + y0 + ") - xy1(" + x1 + "," + y1 + ")" );
tracer.window.messageWindow.setDebugMessage( "pxy0(" + p0.getX() + "," + p0.getY() + ") - pxy1(" + p1.getX() + "," + p1.getY() + ")" );
tracer.window.messageWindow.setDebugMessage( "dxy0(" + dx0 + "," + dy0 + ") - dxy1(" + dx1 + "," + dy1 + ")" );
g.drawLine(x0+ tracer.xBegin ,tracer.yBegin-y0,
x1+ tracer.xBegin,tracer.yBegin-y1);
}
}
}while( max > 0 );
// <--- akira shiozawa
}
}
g.setColor(getForeground());
double end= tracer.myValueEnd-tracer.mCorrect;
double begin= tracer.myValueBegin-tracer.mCorrect;
g.drawString(""+tracer.getDoubleValue(end) , 20, tracer.yEnd - fontInfo.getDescent());
g.drawString(""+tracer.getDoubleValue(begin),20,tracer.yBegin - fontInfo.getDescent());
g.drawString(""+tracer.getDoubleValue(tracer.mxTimeBegin), tracer.xBegin,tracer.yBegin+fontInfo.getAscent());
String str = (String)tracer.getDoubleValue(tracer.mxTimeEnd);
g.drawString(""+tracer.getDoubleValue(tracer.mxTimeEnd) ,
(tracer.xEnd - fontInfo.stringWidth( str ) / 2), tracer.yBegin+fontInfo.getAscent());
}
if(tracer.rflag){
g.setColor(Color.lightGray);
int p1=0;
int p2=0;
int width=0;
int height=0;
if(tracer.rx1>tracer.rx0){
p1=tracer.rx0;
width=tracer.rx1-tracer.rx0;
}else{
p1=tracer.rx1;
width=tracer.rx0-tracer.rx1;
}
if(tracer.ry1>tracer.ry0){
p2=tracer.ry0;
height=tracer.ry1-tracer.ry0;
}else{
p2=tracer.ry1;
height=tracer.ry0-tracer.ry1;
}
g.drawRect(p1,p2,width,height);
}
// cross cursor
if( Tracer.mousex > 0 || Tracer.mousey > 0 )
{
int dx = ((tracer.magFlag == 0)? (int)(Tracer.mousex * tracer.xChange) :
(int)((Tracer.mousex - tracer.mxTimeBegin) * tracer.mxChange));
int dy = ((tracer.magFlag == 0)?
(int)((Tracer.mousey + tracer.correct) * tracer.yChange) :
(int)((Tracer.mousey + tracer.mCorrect - tracer.myValueBegin) * tracer.myChange));
dx += tracer.xBegin;
dy = tracer.yBegin - dy;
//System.out.println( "dx:" + dx + "/dy:" + dy + "/correct:" + tracer.correct + "/yPlot:" + tracer.yPlot + "/mousey:" + Tracer.mousey + "/mousex:" + Tracer.mousex + "/yEnd:" + tracer.yEnd + "/yBegin:" + tracer.yBegin );
if( dx < tracer.xEnd && dy < tracer.yBegin && dx > tracer.xBegin && dy >= tracer.yEnd )
{
tracer.label1.setText(""+ tracer.getDoubleValue(tracer.mousex) +":" +
tracer.getDoubleValue(tracer.mousey));
if( dy > tracer.yEnd )
{
g.setColor(Color.lightGray);
g.drawLine(tracer.xBegin,dy,tracer.xEnd,dy);
g.drawLine(dx,tracer.yEnd,dx,tracer.yBegin);
}
}
else
{
tracer.label1.setText(" : ");
}
}
// 2002.4 akira shiozawa
this.bPainting = false;
}
private boolean getDrawPoints( Point2D.Double p0, Point2D.Double p1 )
{
Point2D.Double pt0 = (Point2D.Double)p0.clone();
Point2D.Double pt1 = (Point2D.Double)p1.clone();
boolean ret = true;
double x,y;
if( tracer.magFlag == 0 )
{
return true;
}
else if( pt0.getX() > tracer.mxTimeEnd || pt1.getX() < tracer.mxTimeBegin ||
( pt0.getY() < tracer.myValueBegin && pt1.getY() < tracer.myValueBegin ) ||
( pt0.getY() > tracer.myValueEnd && pt1.getY() > tracer.myValueEnd ) )
{
return false;
}
if( pt0.getX() < tracer.mxTimeBegin ||
pt0.getY() < tracer.myValueBegin || pt0.getY() > tracer.myValueEnd )
{
if( pt0.getX() < tracer.mxTimeBegin )
{
y = ( (pt1.getX() - tracer.mxTimeBegin) * Math.abs( pt1.getY() - pt0.getY() ))
/ (pt1.getX() - pt0.getX());
y = (pt1.getY() >= pt0.getY())? (pt1.getY() - y) : (pt1.getY() + y);
}
else
{
y = pt0.getY();
}
if( y <= tracer.myValueBegin )
{
x = ((pt1.getX() - pt0.getX()) * Math.abs( tracer.myValueBegin - pt0.getY() )) /
Math.abs( pt1.getY() - pt0.getY() );
x = pt0.getX() + x;
p0.setLocation( x, tracer.myValueBegin );
}
else if( y >= tracer.myValueEnd )
{
x = ((pt1.getX() - pt0.getX()) * Math.abs( pt0.getY() - tracer.myValueEnd )) /
Math.abs( pt1.getY() - pt0.getY() );
x = pt0.getX() + x;
p0.setLocation( x, tracer.myValueEnd );
}
else
{
p0.setLocation( tracer.mxTimeBegin, y );
}
if( p0.getX() > tracer.mxTimeEnd )
{
ret = false;
}
}
if( p1.getX() > tracer.mxTimeEnd ||
p1.getY() > tracer.myValueEnd || p1.getY() < tracer.myValueBegin )
{
if( pt1.getX() > tracer.mxTimeEnd )
{
y = (Math.abs( pt1.getY() - pt0.getY() ) * (tracer.mxTimeEnd - pt0.getX())) /
(pt1.getX() - pt0.getX());
y = (pt1.getY() >= pt0.getY())? (pt0.getY() + y ) : (pt0.getY() - y);
}
else
{
y = pt1.getY();
}
if( y <= tracer.myValueBegin )
{
x = (Math.abs( tracer.myValueBegin - pt1.getY() ) * (pt1.getX() - pt0.getX())) /
Math.abs( pt1.getY() - pt0.getY() );
x = pt1.getX() - x;
p1.setLocation( x, tracer.myValueBegin );
}
else if( y >= tracer.myValueEnd )
{
x = (Math.abs( pt1.getY() - tracer.myValueEnd ) * (pt1.getX() - pt0.getX())) /
Math.abs( pt1.getY() - pt0.getY() );
x = pt1.getX() - x;
p1.setLocation( x, tracer.myValueEnd );
}
else
{
p1.setLocation( tracer.mxTimeEnd, y );
}
if( p1.getX() < tracer.mxTimeBegin )
{
ret = false;
}
}
if( ret )
{
tracer.window.messageWindow.setDebugMessage( "_pxy0(" + p0.getX() + "," + p0.getY() +
") - _pxy1(" + p1.getX() + "," + p1.getY() + ")" );
}
return ret;
}
}